package com.zxinlee.order.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

@LocalTCC
public interface OrderTccAction {

    /**
     * 为了避开Seata的bug ,这里不适应封装的Order对象,
     * 而是使用Order的属性单独传递
     * BusinessActionContextParameter 将paramName属性放入上下文对象,传递到第二阶段
     *
     * @param businessActionContext 使用上下文对象传递业务数据
     * @return
     */

    // 两阶段的业务操作
    @TwoPhaseBusinessAction(name = "OrderTccAction")
    boolean prepare(BusinessActionContext businessActionContext,
                    @BusinessActionContextParameter(paramName = "orderId") Long orderId,
                    Long userId,
                    Long productId,
                    Integer count,
                    BigDecimal money);

    // 源码默认方法
    // String commitMethod() default "commit";
    // String rollbackMethod() default "rollback";
    boolean commit(BusinessActionContext businessActionContext);

    boolean rollback(BusinessActionContext businessActionContext);
}
